package com.itboye.sunsun.me.ui;

import java.text.SimpleDateFormat;
import java.util.List;

import com.itboye.sunsunhome.R;
import com.itboye.sunsun.application.App;
import com.itboye.sunsun.beans.WoDeHuiTieBean.WoDeHuiTieItemBean;
import com.itboye.sunsun.beans.WoDeZhuTiBean.ZhuTiItemBean;
import com.itboye.sunsun.constants.NetPublicConstant;
import com.itboye.sunsun.utils.XImageLoader;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MytieziAdapter extends BaseAdapter {

	List<WoDeHuiTieItemBean> dataList;

	public MytieziAdapter(List<WoDeHuiTieItemBean> dataList) {
		this.dataList = dataList;
	}

	@Override
	public int getCount() {

		return dataList.size();
	}

	@Override
	public Object getItem(int position) {

		return null;
	}

	@Override
	public long getItemId(int position) {

		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			convertView = LayoutInflater.from(App.ctx).inflate(
					R.layout.item_wode_huitie, null);
			holder = new ViewHolder();
			holder.head = (ImageView) convertView.findViewById(R.id.head);

			holder.name = (TextView) convertView.findViewById(R.id.name);
			holder.time = (TextView) convertView.findViewById(R.id.time);
			holder.content = (TextView) convertView.findViewById(R.id.content);
			holder.zan = (TextView) convertView.findViewById(R.id.zan);
			holder.commont = (TextView) convertView.findViewById(R.id.commont);
			holder.tvhuifu = (TextView) convertView.findViewById(R.id.tvhuifu);
			holder.wohuifudepinglun = (TextView) convertView
					.findViewById(R.id.wohuifudepinglun);
			// holder.imgsContainer=(ViewGroup)
			// convertView.findViewById(R.id.imgsContainer);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		WoDeHuiTieItemBean bean = dataList.get(position);
		try {

			if (bean.getHead() == "" || bean.getHead() == null) {
				Bitmap bitmap = BitmapFactory.decodeResource(
						App.ctx.getResources(), R.drawable.defaultimage);
				holder.head.setImageBitmap(bitmap);
				holder.name.setText(bean.getName());

			} else {
				holder.head.setImageBitmap(null);
				// if (!bean.getUserInfo().getHead().startsWith("http")) {
				XImageLoader.load(bean.getHead(), holder.head);
				holder.name.setText(bean.getName());
				// } else {
				// XImageLoader.load(bean.getHead(),
				// holder.head);
				// holder.name.setText(bean.getName());
				// }
			}
		} catch (Exception e) {
			// TODO: handle exception
		}

		holder.time.setText(new SimpleDateFormat("yyyy-MM-dd").format(Long
				.parseLong(bean.getDateline())*1000));
		holder.content.setText(bean.getComment());
		holder.wohuifudepinglun.setText(bean.getContent());
		holder.tvhuifu.setText("回复"+bean.getWhoname()+":");
		return convertView;
	}

	class ViewHolder {
		ImageView head;

		TextView name, tvhuifu;
		TextView time;
		TextView content;
		TextView zan;
		TextView commont;
		TextView wohuifudepinglun;
		// ViewGroup imgsContainer;
	}

}
